主题
打开注册表键 - RegistryOpenKey
函数简介
打开已存在的注册表键,用于后续读取或修改操作。
接口名称
RegistryOpenKeyDLL调用
cpp
int64_t RegistryOpenKey(int64_t instance, int32_t rootKey, const char* subKey);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| rootKey | 整数型 | 根键类型:0 HKEY_CLASSES_ROOT、1 HKEY_CURRENT_USER、2 HKEY_LOCAL_MACHINE、3 HKEY_USERS、4 HKEY_CURRENT_CONFIG |
| subKey | 字符串 | 子键路径,例如 "Software\Microsoft\Windows" |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// rootKey=1 表示 HKEY_CURRENT_USER
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
std::string version = ola.RegistryGetString(key, "Version");
// 读取完成后关闭句柄
ola.RegistryCloseKey(key);
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
long key = ola.RegistryOpenKey(1, @"Software\OLAPlug");
if (key != 0)
{
string version = ola.RegistryGetString(key, "Version");
// 读取完成后关闭句柄
ola.RegistryCloseKey(key);
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
key = ola.RegistryOpenKey(1, r"Software\OLAPlug")
if key != 0:
version = ola.RegistryGetString(key, "Version")
# 读取完成后关闭句柄
ola.RegistryCloseKey(key)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
String version = ola.RegistryGetString(key, "Version");
// 读取完成后关闭句柄
ola.RegistryCloseKey(key);
}cpp
var ola = com("OlaPlug.OlaSoft")
var key = ola.RegistryOpenKey(1, "Software\\OLAPlug")
if(key) {
var version = ola.RegistryGetString(key, "Version")
// 读取完成后关闭句柄
ola.RegistryCloseKey(key)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
key = ola.RegistryOpenKey(1, "Software\OLAPlug")
If key <> 0 Then
version = ola.RegistryGetString(key, "Version")
// 读取完成后关闭句柄
ola.RegistryCloseKey(key)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
key = ola.RegistryOpenKey (1, “Software\\OLAPlug“)
.如果真 (key ≠ 0)
version = ola.RegistryGetString (key, "Version")
// 读取完成后关闭句柄
ola.RegistryCloseKey (key)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if(key){
var version = ola.RegistryGetString(key, "Version");
// 读取完成后关闭句柄
ola.RegistryCloseKey(key);
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 key = ola.RegistryOpenKey(1, "Software\\OLAPlug")
如果真 (key ≠ 0)
{
文本型 version = ola.RegistryGetString(key, "Version")
// 读取完成后关闭句柄
ola.RegistryCloseKey(key)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long key = ola.RegistryOpenKey(1, "Software\\OLAPlug");
if (key != 0) {
std::string version = ola.RegistryGetString(key, "Version");
// 读取完成后关闭句柄
ola.RegistryCloseKey(key);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long key = RegistryOpenKey(instance, 1, "Software\\OLAPlug");
if (key != 0) {
// RegistryGetString(instance, key, "Version", 0);
RegistryCloseKey(instance, key);
}csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
long key = RegistryOpenKey(instance, 1, @"Software\OLAPlug");
if (key != 0)
{
// RegistryGetString(instance, key, "Version", 0);
RegistryCloseKey(instance, key);
}python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
key = ola.RegistryOpenKey(instance, 1, b"Software\\OLAPlug")
if key:
// RegistryGetString(instance, key, "Version", 0);
ola.RegistryCloseKey(instance, key)返回值
长整数型。成功返回注册表键句柄(非0值),失败返回 0。
注意事项
- 仅在键已存在时返回有效句柄,键不存在将返回 0。
- 使用完成后必须调用 RegistryCloseKey 释放句柄。
- 如果需要在键不存在时自动创建,请使用 RegistryCreateKey。
